/**
 * 
 */
package com.geezdata.cps.ttk.domain.factory;

import java.util.Date;

import com.geezdata.cps.base.utils.BeanUtil;
import com.geezdata.cps.ttk.common.request.CreateOrUpdateTaskRequest;
import com.geezdata.cps.ttk.common.vo.TaskReqVO;
import com.geezdata.cps.ttk.domain.domain.Task;

/**
 * @author sszheng
 * @date 创建时间：2018年10月29日 下午3:35:17
 *
 */
public class TaskFactory {
	public static Task newInstance(CreateOrUpdateTaskRequest request , Task exsitsTask) {
		TaskReqVO taskReqVO = request.getTask();
		Task task = BeanUtil.convert(taskReqVO, Task.class);
    	Date now = new Date();
    	String currentUser = request.getCurrentUser();
    	
    	if (exsitsTask == null) {
    		task.setRemainedTaskNum(task.getTaskNum());
    		task.setCreatedUser(currentUser);
    		task.setCreatedAt(now);
    		task.setStatus(1);
    	} else {
    		task.setGoodsId(exsitsTask.getGoodsId());
    	}
    	
    	task.setUpdatedUser(currentUser);
    	task.setUpdatedAt(now);
        return task;
	}
}
